package com.laizhenghua.eureka.controller;

import com.laizhenghua.commons.entity.CommonResult;
import com.laizhenghua.commons.entity.PaymentEntity;
import com.laizhenghua.eureka.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @date: 2022/2/11 21:37
 */
@Slf4j
@RestController
@RequestMapping(path = "/payment")
public class PaymentController {
    @Value("${server.port}")
    private String serverPort;

    @Autowired
    private PaymentService paymentService;

    @RequestMapping(path = "/getPaymentById/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public CommonResult<PaymentEntity> getPaymentEntityById(@PathVariable(value = "id") Integer id) {
        PaymentEntity entity = paymentService.getById(id);
        return new CommonResult<>(200, "server port -> " + serverPort, entity);
    }

    @RequestMapping(path = "/timeoutTest", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public CommonResult<String> timeoutTest() {
        try {
            Thread.sleep(60000);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return new CommonResult<>(200, "timeout test", "sleep 1 minute");
    }
}
